<template>
  <div class="app-container">
  <div class="filter-container">
        <el-button type="primary" @click="refreshClick()">刷新</el-button>
        <el-input clearable v-model="search.number" placeholder="车牌号码" style="width: 170px;margin-left:10px;"></el-input>
        <el-input clearable v-model="search.name" placeholder="联系人" style="width: 170px;margin-left:10px;"></el-input>
        <el-input clearable v-model="search.phone" placeholder="联系电话" style="width: 170px;margin:0 5px;"></el-input>
        <el-date-picker v-model="search.daterange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>

        <el-button type="primary" icon="el-icon-search" @click="searchClick()" style="margin-left:10px;">查询</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" 
      border fit highlight-current-row stripe 
      style="width: 100%">
      <el-table-column align="center" label="序" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row._id }}</span>
        </template>
      </el-table-column>
     <el-table-column  min-width="100" align="center" label="车牌号码">
        <template slot-scope="scope">
          <span>{{ scope.row.licenseplate }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="具体车型">
        <template slot-scope="scope">
          <span>{{ scope.row.carname }}</span>
        </template>
      </el-table-column>
      
      <el-table-column  min-width="100" align="center" label="车身颜色">
        <template slot-scope="scope">
          <span>{{ scope.row.carcolor }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="客户姓名">
        <template slot-scope="scope">
          <span>{{ scope.row.customername }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="联系电话">
        <template slot-scope="scope">
          <span>{{ scope.row.customerphone }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="出厂日期">
        <template slot-scope="scope">
          <span>{{ scope.row.productiondate }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="维修类别">
        <template slot-scope="scope">
          <span>{{ scope.row.repairtype }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="是否保养">
        <template slot-scope="scope">
          <span>{{ scope.row.keepfit}}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="接车员">
        <template slot-scope="scope">
          <span>{{ scope.row.taker }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="分配日期">
        <template slot-scope="scope">
          <span>{{ scope.row.appointtime }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="预约员">
        <template slot-scope="scope">
          <span>{{ scope.row.appointguider }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="回访记录">
        <template slot-scope="scope">
          <span @click="rowRevistCountClick(scope.row.id)">{{ scope.row.revisitcount }}</span>
        </template>
      </el-table-column>
      
      <el-table-column  min-width="100" align="center" label="状态">
        <template slot-scope="scope">
          <span>{{ scope.row.state | parseRevisitResult }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="备注">
        <template slot-scope="scope">
          <span>{{ scope.row.remark }}</span>
        </template>
      </el-table-column>
      <el-table-column  min-width="100" align="center" label="日期">
        <template slot-scope="scope">
          <span>{{ scope.row.createtime | parseTime('{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="操作"  width="120" fixed="right">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="rowRevisitClick(scope.row.id)">回访</el-button>
          
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.rows" @pagination="fetchData" />

<!-- 回访 -->
<el-dialog :title="dialog.title" :visible.sync="dialog.visible"  width="700px">
    <div class="ci">
        <div class="item">
            <span class="name required">回访时间：</span>
            <span class="value">
                <el-date-picker v-model="dialog.data.revisittime" type="datetime" ></el-date-picker>
            </span>
        </div>
        <div class="item hauto">
            <span class="name required">回访内容：</span>
            <span class="value">
                <el-input type="textarea" rows="3" v-model="dialog.data.revisitcontent" style="width:100%;"></el-input>
            </span>
        </div>
        <div class="item">
            <span class="name required">结果</span>
            <span class="value">
                <el-select v-model="dialog.data.revisitresult" clearable placeholder="--" style="width: 220px;">
                    <el-option 
                    v-for="(item,index) in selectOptions.revisitresult"
                    :key="index"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
                
            </span>
        </div>
        
    </div>
    <div slot="footer" class="dialog-footer">
        <el-button @click="dialog.visible = false">取 消</el-button>
        <el-button type="primary" @click="saveRevisitClick()" :loading="dialog.saveloading">保 存</el-button>
    </div>
</el-dialog>
<!-- end 回访 -->

<!-- 回访记录 -->
<el-dialog :title="dialogHistory.title" :visible.sync="dialogHistory.visible"  width="700px">
    <div class="ci">
        <el-table v-loading="dialogHistory.listLoading" :data="dialogHistory.list" 
          border fit highlight-current-row stripe 
          style="width: 100%">
          <el-table-column align="center" label="序" width="80">
            <template slot-scope="scope">
              <span>{{ scope.row._id }}</span>
            </template>
          </el-table-column>
        <el-table-column  min-width="100" align="center" label="跟进人员">
            <template slot-scope="scope">
              <span>{{ scope.row.operator }}</span>
            </template>
          </el-table-column>
          <el-table-column  min-width="100" align="center" label="内容">
            <template slot-scope="scope">
              <span>{{ scope.row.content }}</span>
            </template>
          </el-table-column>
          <el-table-column  min-width="100" align="center" label="结果">
            <template slot-scope="scope">
              <span>{{ scope.row.result }}</span>
            </template>
          </el-table-column>
          <el-table-column  min-width="100" align="center" label="时间">
            <template slot-scope="scope">
              <span>{{ scope.row.createtime |parseTime }}</span>
            </template>
          </el-table-column>
        </el-table>
        
    </div>
    <div slot="footer" class="dialog-footer">
        <el-button  type="primary" @click="dialogHistory.visible = false">关 闭</el-button>
        
    </div>
</el-dialog>
<!-- end 回访记录 -->

  </div>
</template>

<script>
import * as keepfitappointApi from '@/api/aftersale/keepfitappoint'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import * as enumHelper from '@/utils/enum'

export default {
    components: { Pagination },
    data(){
        return{
          search:{ 
              number:'',
              customer:'',
              phone:'',
              daterange:'',
          },
          listQuery: {
                page: 1,
                rows: 20,
                name:'',
                phone:'',
                state:-1,
                daterange:''
          },
          list:null,
          listLoading:false,
          total:0,
          selectOptions:{
            revisitresult:[]
          },

          dialog:{
              visible:false,
              saveloading:false,
              title:'分配',
              data:{
                  id:'',
                  taker:''
              }
          },
          dialogHistory:{
              visible:false,
              saveloading:false,
              title:'回访记录',
              list:null,
              listLoading:false,
          }
        }
    },
    created(){
        var that=this;
        //初始化下拉菜单
        enumHelper.initOptions(that.selectOptions.revisitresult,enumHelper.aftersale.revisitResult);
        that.fetchData();
    },
    filters:{
      parseRevisitResult(val){
        return enumHelper.aftersale.revisitResult.getName(val);
      }

    },
    methods:{
        fetchData(){
          var that=this;
            keepfitappointApi.getAppointFollwList({}).then(res=>{
              if(res.data){
                that.list=[...res.data.items.map((item,index)=>{
                  item._id=index+1;
                  return item;
                })];
              }
            })
        },
        refreshClick(){
          this.fetchData();
        },
        
        saveRevisitClick(){
          var that=this;
          that.dialog.saveloading=true;
        },
        rowRevisitClick(id){
          var that=this;
          that.dialog.visible=true;

          
        },
        rowRevistCountClick(id){
            var that=this;
            that.dialogHistory.visible=true;
        }
    }
}
</script>

<style>

</style>